const http = require("http");

// 创建http对应的服务器
const server = http.createServer((request, response) => {
    // request 实际是readable可读流
    request.setEncoding("utf-8"); // 参数编码方式

    let isLogin = false;
    req.on("data", (data) => {
        // 拿到请求信息 并对请求信息做出判断
        const dataString = data;
        const loginInfo = JSON.parse(dataString);
        if (loginInfo.name === "coderwhy" && loginInfo.password === "123456") {
            isLogin = true;
        } else {
            isLogin = false;
        }
    });

    req.on("end", () => {
        if (isLogin) {
            res.end("登录成功, 欢迎回来~");
        } else {
            res.end("账号或者密码错误, 请检测登录信息~");
        }
    });

    response.end("hello node");
});

server.listen(8000, () => {
    console.log("开启服务器成功");
});
